// pages/morejob/cityselect/cityselect.js
import data from "../../../utils/city"
Page({
  data: {
    searchValue: "",
    currentCity: "",
    city: data.city,
    hotCity: [{
        id: 1,
        name: "北京"
      },
      {
        id: 2,
        name: "上海"
      },
      {
        id: 3,
        name: "广州"
      },
      {
        id: 4,
        name: "深圳"
      },
      {
        id: 5,
        name: "重庆"
      },
      {
        id: 6,
        name: "武汉"
      },
      {
        id: 7,
        name: "天津"
      },
      {
        id: 8,
        name: "长沙"
      },
      {
        id: 9,
        name: "南京"
      },
    ],
    searchList: []
  },
  onLoad: function (options) {},
  onShow: function () {
    // 获取用户授权信息
    wx.getLocation({
      type: "gcj02",
      success: (data) => {
        this.setData({
          latitude: data.latitude,
          longitude: data.longitude
        });
        getApp().globalData.http.getPosition({
          location: data.latitude + "," + data.longitude
        }).then(res => {
          this.setData({
            currentCity: res.result.ad_info.city
          });
        });
      },
      fail: () => {}
    });
    wx.getSetting({
      success: (res) => {
        console.log("授权信息", res.authSetting)
        if (!res.authSetting["scope.userLocation"] && res.authSetting["scope.userLocation"] != undefined) {
          getApp().globalData.vant.dialog.confirm({
            title: "温馨提示",
            message: "位置授权是为了给您定位居住小区，确保小区及人员信息的真实安全~",
            showCancelButton: false,
            confirmButtonText: "授权登录",
            confirmButtonOpenType: "openSetting",
            confirmButtonColor: "#33B868"
          }).then(() => {});
        } else {}
      },
      fail: () => {}
    });
  },
  searchCancel() {
    this.setData({
      searchValue: ""
    })
  },
  selCity(e) {
    wx.setStorageSync("city_select", e.currentTarget.dataset.name);
    wx.navigateBack();
  },
  input() {
    let city = this.data.city;
    let key = this.data.searchValue;
    let result = [];
    city.forEach(e => {
      e.lists.forEach(ee => {
        if (ee.includes(key)) {
          result.push(ee);
        }
      });
    });
    this.setData({
      searchList: result
    });
  }
})